Xbasic
Handling Errors with the SQL::CallResult Object
Description
AlphaDAO contains a special object named SQL::CallResult to help you diagnose problems. Suppose you take the following script, which works, and change the name of the database from "alphasports.mdb" to "alpha.mdb".
Before:
dim conn as SQL::Connection ? conn.open("{A5API=Access,FileName='C:\Program Files\a5v8\MDBFiles\Alphasports.mdb',UserName='Admin'}") = .T.
After:
dim conn as SQL::Connection ? conn.open("{A5API=Access,FileName='C:\Program Files\a5v8\MDBFiles\Alpha.mdb',UserName='Admin'}") = .F.
Note that the .Open() method returned .F. (FALSE), meaning that an error occurred. If you want to know what went wrong, take a look at the connection object's .CallResult property.
? conn.CallResult = API = "" Canceled = .F. Code = 195 Error = .T. LastInsertedIdentity = NativeCode = -1 NativeText = [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. SQL State is: HY000 [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed SQL State is: IM006 RowsAffected = 0 Success = .F. Syntax = "" Text = Database API specific error Your database has returned the following error code and description to Alpha Anywhere. Consult your database documentation for further information. -1 - '[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. SQL State is: HY000 [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed SQL State is: IM006' Warnings = .F.
Or to narrow things down, look at the CallResult.text property.
? conn.CallResult.Text = Database API specific error Your database has returned the following error code and description to Alpha Anywhere. Consult your database documentation for further information. -1 - '[Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'. SQL State is: HY000 [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed SQL State is: IM006'
AlphaDAO does its best to interpret the error messages returned by back-end databases into meaningful statements that you can use.
conn.close()
Limitations
Desktop applications only.
See Also